//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { scrollMixin } from "utils/mixin";
export default {
  name: "",
  //import引入的组件需要注入到对象中才能使用
  components: {},
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      goodsList: [],
      page: 1,
      total_page: 0,
      isLoadMore: true,
      price: "",
      levelName: "",
      pushNum: 0,
      selfPrice: 0,
      havePushNum: 0,
      applyBackground: ""
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getApplydata() {
      //会员信息
      $http
        .post("plugin.area-dividend.api.upgrade.index", {}, "loading")
        .then(res => {
          if (res.result === 1) {
            if(res.data.apply) {
              return this.$dialog.confirm({
                title: '提示',
                message: '您已满足申请条件',
                confirmButtonText: '去申请'
              })
                .then(() => {
                  this.$router.push(this.fun.getUrl("applyRegionalAgency"));
                })
                .catch(() => {
                  // on cancel
                });
            }
            let data = res.data;
            this.goodsList = data.goods_list?.data;
            this.levelName = data.level_name;
            this.price = data.price;
            this.pushNum = data.push_num;
            this.selfPrice = data.self_price;
            this.havePushNum = data.have_push_num;
            this.applyBackground = data.apply_background;
            this.isLoadMore = true;
            this.total_page = data.goods_list.last_page;
            if (!this.total_page) {
              this.page = 0;
            }
          } else {
            this.$dialog.alert({
              message: res.msg
            });
            // this.$toast(res.msg);
          }
        })
        .catch(err => {
          console.log("getUserData::err", err);
        });
    },
    goodsNav(id) {
      this.$router.push(this.fun.getUrl("goods", { id: id }));
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let query = {
          page: this.page,
          basic_info: 1
        };
        $http.post("plugin.area-dividend.api.upgrade.index", query, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let data = res.data;
              let goodsList = data.goods_list.data;
              this.goodsList = [...this.goodsList, ...goodsList]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getApplydata();
  }
};
